﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text.RegularExpressions;
public partial class Manage_Emp1_Record1Detail : AdminPageBase
{
    int id;
	private string returnURL;
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckAdmin();
        GetUserPermisions();
        GetClassRecordId();
		returnURL = Request.QueryString["returnURL"].ToString();
        if (!IsPostBack)
        {
            // 正确的属性设置方法
            this.GridView1.Attributes.Add("SortExpression", "RecordId");
            this.GridView1.Attributes.Add("SortDirection", "ASC");
            this.GridView2.Attributes.Add("SortExpression", "ClassId");
            this.GridView2.Attributes.Add("SortDirection", "ASC");
            DataTable dt = new DataTable();
            dt.Columns.Add("RecordId");
            dt.Columns.Add("ClassTypeName");
            dt.Columns.Add("ClassCode");
            dt.Columns.Add("ClassName");
            dt.Columns.Add("ClassId");
            dt.Columns.Add("Satisficing");
            dt.Columns.Add("TeacherName");
            dt.Columns.Add("Time");
            dt.Columns.Add("OpenTime");
            dt.Columns.Add("FactTimes");
            dt.Columns.Add("CenterName");
            dt.Columns.Add("CenterId");
            dt.Columns.Add("");

            GridviewControl.GridViewDataBind(this.GridView1, dt);
            GridviewControl.ResetGridView(this.GridView1);
            BindRecord();
        }
    }

    protected void GetClassRecordId()
    {
        if (Request.QueryString["id"] == null)
        {
            id = 0;

        }
        else
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
           
        }
        if (Request.QueryString["Num"] == null)
        {
            lblNum.Text = "";
        }
        else
            lblNum.Text = Request.QueryString["Num"].ToString();
        if (Request.QueryString["Title"] == null)
            txttitle.Text = "";
        else
            txttitle.Text = Request.QueryString["Title"].ToString();
    }
    protected void CheckAdmin()
    {
        if (AdminSessionHelper.UserDetails == null)
        {
            JsHelper.TopAlertRedirect("请先登录", "../login.aspx", this.Page);
        }
    }

    protected void BindRecord()
    {
      
        if (id != 0)
        {
            DataSet dsemp = jtDataAccess.GetGetRecordByClassRecordId(id);
            if (CoreTools.CheckDataSet(dsemp))
            {
                // 获取GridView排序数据列及排序方向
                string sortExpression = this.GridView1.Attributes["SortExpression"];
                string sortDirection = this.GridView1.Attributes["SortDirection"];

                // 根据GridView排序数据列及排序方向设置显示的默认数据视图
                if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
                {
                    dsemp.Tables[0].DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
                }

                // GridView绑定并显示数据
                GridviewControl.GridViewDataBind(this.GridView1, dsemp.Tables[0]);
                Button1.Enabled = true;
                selectAll1.Enabled = true;
                
            }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("RecordId");
                dt.Columns.Add("ClassTypeName");
                dt.Columns.Add("ClassCode");
                dt.Columns.Add("ClassName");
                dt.Columns.Add("ClassId");
                dt.Columns.Add("Satisficing");
                dt.Columns.Add("TeacherName");
                dt.Columns.Add("Time");
                dt.Columns.Add("OpenTime");
                dt.Columns.Add("FactTimes");
                dt.Columns.Add("CenterName");
                dt.Columns.Add("CenterId");
                dt.Columns.Add("");

                GridviewControl.GridViewDataBind(this.GridView1, dt);
                Button1.Enabled = false;
                selectAll1.Enabled = false;
            }
        }
    }
    protected void btnAddClass_Click(object sender, EventArgs e)
    {
        if(id!=0)
        {
            DataSet dsc = jtDataAccess.SearchCenter("", 10, 0, "Name", "ASC");
            if (CoreTools.CheckDataSet(dsc))
            {
                ddlcenter.DataSource = dsc;
                ddlcenter.DataTextField = "Name";
                ddlcenter.DataValueField = "CenterId";
                ddlcenter.DataBind();
            }
            ListItem item = new ListItem("请选择所属指挥中心","0");
            ddlcenter.Items.Insert(0,item);
            int flag = 0;
            flag = SaveClassRecord();
            if (flag > 0)
            {
                divadd_class.Visible = true;
                DataSet ds = jtDataAccess.SearchClassType("", 10, 0, "Name", "Asc");
                if (CoreTools.CheckDataSet(ds))
                {
                   ddlclassType.DataSource = ds;
                   ddlclassType.DataTextField = "Name";
                   ddlclassType.DataValueField = "ClassTypeId";
                   ddlclassType.DataBind();
                }
                ListItem item1 = new ListItem("选择课程类型", "0");
                ddlclassType.Items.Insert(0, item1);
                DataTable dt = new DataTable();
                dt.Columns.Add("ClassId");
                dt.Columns.Add("ClassTypeName");
                dt.Columns.Add("Code");
                dt.Columns.Add("Name");
                dt.Columns.Add("Time");
                dt.Columns.Add("");
                GridviewControl.GridViewDataBind(this.GridView2, dt);
            }
        }
        GridviewControl.ResetGridView(this.GridView1);
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        int flag = SaveClassRecord();
        switch (flag)
        {
            case -1:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作失败，已经存在相同编号的课程！"), false);
                break;
            case 0:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作失败！"), false);
                break;
            default:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);
                break;
        }
        GridviewControl.ResetGridView(this.GridView1);
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected int SaveClassRecord()
    {
        int flag = 0;
        string Num = lblNum.Text;
        string title = txttitle.Text.Trim();
        if (!CoreTools.ProcessSqlStr(title, 0))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
            txttitle.Focus();
        }
        else
        {
            flag = jtDataAccess.OpClassRecord(JTDataAccess.OpType.Update,id, 1, Num, title, int.Parse(AdminSessionHelper.UserDetails["UserId"].ToString()),0);

        }
        return flag;

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindRecord();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            LinkButton BtnDelete = (LinkButton)e.Row.Cells[10].Controls[2];
            if (BtnDelete.Text == "删除")
            {
                ((LinkButton)e.Row.Cells[10].Controls[2]).Attributes.Add("onclick", "javascript:return confirm('您确定要删除该记录吗？')");
            }

        }
        DropDownList ddlcenter = (DropDownList)e.Row.FindControl("ddlcenter");
        HiddenField hdfcenterid = (HiddenField)e.Row.FindControl("hdfcenterId");
        if (ddlcenter != null)
        {
            DataSet ds = jtDataAccess.SearchCenter("", 10, 0, "Name", "ASC");
            if (CoreTools.CheckDataSet(ds))
            {
                ddlcenter.DataSource = ds;
                ddlcenter.DataTextField = "Name";
                ddlcenter.DataValueField = "CenterId";
                ddlcenter.DataBind();
            }
            if (hdfcenterid != null && hdfcenterid.Value != "")
                ddlcenter.SelectedValue = hdfcenterid.Value;

        }
        if (edit == 1)
            ((CommandField)GridView1.Columns[10]).ShowEditButton = true;
        else
            ((CommandField)GridView1.Columns[10]).ShowEditButton = false;
        if (delete == 1)
            ((CommandField)GridView1.Columns[10]).ShowDeleteButton = true;
        else
            ((CommandField)GridView1.Columns[10]).ShowDeleteButton = false;

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        UserType ut = new UserType();//用户自定义类型
        DataTable RecordTable = ut.GetRecordTableType();

        DataRow RecordTableRow;
        int RecordId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());


        RecordTableRow = RecordTable.NewRow();
        RecordTableRow["RecordId"] = RecordId;
        RecordTable.Rows.Add(RecordTableRow);

        RecordTable.AcceptChanges();
        int flag = jtDataAccess.OpRecord(JTDataAccess.OpType.Delete, RecordTable);
        switch (flag)
        {
            case 0:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除失败！"), false);
                break;

            case 1:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除成功！"), false);
                break;
            default:
                break;
        }

        GridView1.EditIndex = -1;
        BindRecord();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindRecord();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        int flag = 0;
        int RecordId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
        int classid = Convert.ToInt32(((HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdfClassId")).Value);
        int centerId = Convert.ToInt32(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlcenter")).SelectedValue);
        int Satisficing = -1;
        string TeacherName = "";
        decimal time =0;
        int FactTimes =0;
        string opentime ="";
        TextBox cSatisficing = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtSatisficing");
        TextBox cTeacherName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTeacherName");
        TextBox ctime = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTime");
        TextBox copentime = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtOpenTime");
        TextBox cFactTimes = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtFactTimes");
        if (cSatisficing.Text == "")
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("请填写课程满意程度！"), false);
            cSatisficing.Focus();
        }
        else if (!Regex.IsMatch(cSatisficing.Text.ToString(), "^(?:0|[1-9][0-9]?|100)$"))
        {
             ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("课程满意程度只能为0到100的正数！"), false);
             cSatisficing.Focus();
        }
        else
            Satisficing=Convert.ToInt32(cSatisficing.Text.Trim());

        if (cTeacherName.Text == "")
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("请填写导师姓名！"), false);
            cTeacherName.Focus();
        }
        else  if (!CoreTools.ProcessSqlStr(TeacherName, 0))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
        }
        else
            TeacherName=cTeacherName.Text.Trim();
        if (ctime.Text == "")
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("请填写课程小时数！"), false);
            ctime.Focus();
        }
        else 
            time = Convert.ToDecimal(ctime.Text.Trim());
        if (cFactTimes.Text == "")
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("请填写培训人次！"), false);
            cFactTimes.Focus();
        }
        else if (!Regex.IsMatch(cFactTimes.Text.ToString(), "^[0-9]*[1-9][0-9]*$"))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("培训人次必须为正整数！"), false);
            cFactTimes.Focus();
        }
        else
            FactTimes = Convert.ToInt32(cFactTimes.Text.Trim());
        if (copentime.Text == "")
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("请填写开课时间！"), false);
            copentime.Focus();
        }
        else if(!Regex.IsMatch(copentime.Text.ToString(), "^([2-9]\\d{3})(0[1-9]|1[0-2])$"))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("开课时间格式不正确,正确格式形如：201206！"), false);
            copentime.Focus();
        }
        else 
            opentime=copentime.Text.Trim();
      

        if(Satisficing!=-1&&TeacherName!=""&&time!=0&&opentime!=""&&FactTimes!=0)
        {
            UserType ut = new UserType();//用户自定义类型
            DataTable RecordTable = ut.GetRecordTableType();
            DataRow RecordTableRow;
            RecordTableRow = RecordTable.NewRow();
            RecordTableRow["RecordId"] = RecordId;
            RecordTableRow["ClassRecordId"] = id;
            RecordTableRow["EmpTypeId"] =1;
            RecordTableRow["ClassId"] = classid;
            RecordTableRow["Satisficing"] = Satisficing;
            RecordTableRow["TeacherName"] = TeacherName;
            RecordTableRow["Time"] = time;
            RecordTableRow["FactTimes"] = FactTimes;
            RecordTableRow["CenterId"] = centerId;
            RecordTableRow["OpenTime"] = opentime;
            RecordTable.Rows.Add(RecordTableRow);
            flag = jtDataAccess.OpRecord(JTDataAccess.OpType.Update, RecordTable);
            switch (flag)
            {
                case 1:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);
                    break;
                case 0:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作失败，请重试！"), false);
                    break;
                default:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);

                    break;
            }
            GridView1.EditIndex = -1;
            BindRecord();
        }
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        // 从事件参数获取排序数据列
        string sortExpression = e.SortExpression.ToString();

        // 假定为排序方向为“顺序”
        string sortDirection = "ASC";

        // “ASC”与事件参数获取到的排序方向进行比较，进行GridView排序方向参数的修改
        if (sortExpression == this.GridView1.Attributes["SortExpression"])
        {
            //获得下一次的排序状态
            sortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
        }

        // 重新设定GridView排序数据列及排序方向
        this.GridView1.Attributes["SortExpression"] = sortExpression;
        this.GridView1.Attributes["SortDirection"] = sortDirection;

        this.BindRecord();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void btnMassAdd_Click(object sender, EventArgs e)
    {
        string OpenTime = txtOpenTime.Text.Trim();
        int centerid = Convert.ToInt32(ddlcenter.SelectedValue);
        if (OpenTime != "" && !CoreTools.ProcessSqlStr(OpenTime, 0))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
        }
        else
        {
            UserType ut = new UserType();//用户自定义类型
            DataTable RecordTable = ut.GetRecordTableType();
            int count = 0;
            DataRow RecordTableRow;
            for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)GridView2.Rows[i].FindControl("chkID");
                HiddenField hdfClssId = (HiddenField)GridView2.Rows[i].FindControl("hdfClassId");
                decimal time = Convert.ToDecimal(((Label)GridView2.Rows[i].FindControl("lblTime")).Text.Trim());
                if (cbox.Checked == true && hdfClssId != null && hdfClssId.Value != "")
                {
                    count++;
                    RecordTableRow = RecordTable.NewRow();
                    RecordTableRow["RecordId"] = 0;
                    RecordTableRow["ClassRecordId"] = id;
                    RecordTableRow["EmpTypeId"] = 1;
                    RecordTableRow["ClassId"] = Convert.ToInt32(hdfClssId.Value);
                    RecordTableRow["Satisficing"] = 0;
                    RecordTableRow["TeacherName"] = "";
                    RecordTableRow["Time"] = time;
                    RecordTableRow["FactTimes"] = 0;
                    RecordTableRow["CenterId"] = centerid;
                    RecordTableRow["OpenTime"] = OpenTime;
                    RecordTable.Rows.Add(RecordTableRow);
                }
            }
            if (count == 0)
            {
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("您还未选择任何一项！"), false);
            }
            else
            {
                RecordTable.AcceptChanges();
                int flag = jtDataAccess.OpRecord(JTDataAccess.OpType.Insert, RecordTable);

                switch (flag)
                {
                    case 0:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("添加失败！"), false);
                        break;

                    case 1:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("添加成功！"), false);
                        BindRecord();
                        BindSelectClass();
                        break;

                    default:
                        break;
                }
                selectAll.Checked = false;
            }
        }
        GridviewControl.ResetGridView(this.GridView1);
    }
    protected void selectAll_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView2.Rows[i].FindControl("chkID");
            if (selectAll.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
        GridviewControl.ResetGridView(this.GridView1);
    }
    protected void btnDeleteMass_Click(object sender, EventArgs e)
    {
        UserType ut = new UserType();//用户自定义类型
        DataTable RecordTable = ut.GetPlanFinishTableType();
        int count = 0;
        DataRow RecordTableRow;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkID1");
            HiddenField hdfRecordId = (HiddenField)GridView1.Rows[i].FindControl("hdfRecordId");
            if (cbox.Checked == true && hdfRecordId != null && hdfRecordId.Value != "")
            {

                count++;
                RecordTableRow = RecordTable.NewRow();
                RecordTableRow["RecordId"] = hdfRecordId.Value;
                RecordTable.Rows.Add(RecordTableRow);
            }
        }
        if (count == 0)
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("您还未选择任何一项！"), false);
        }
        else
        {
            RecordTable.AcceptChanges();
            int flag = jtDataAccess.OpPlanFinish(JTDataAccess.OpType.Delete, RecordTable,0);

            switch (flag)
            {
                case 0:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除失败！"), false);
                    break;

                case 1:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除成功！"), false);
                    BindRecord();
                    break;

                default:
                    break;
            }
            selectAll1.Checked = false;
        }
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void selectAll1_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkID1");
            if (selectAll1.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
        GridviewControl.ResetGridView(this.GridView2);
    }
   
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

        }
      
    }
    protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
    {
        // 从事件参数获取排序数据列
        string sortExpression = e.SortExpression.ToString();

        // 假定为排序方向为“顺序”
        string sortDirection = "ASC";

        // “ASC”与事件参数获取到的排序方向进行比较，进行GridView排序方向参数的修改
        if (sortExpression == this.GridView2.Attributes["SortExpression"])
        {
            //获得下一次的排序状态
            sortDirection = (this.GridView2.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
        }

        // 重新设定GridView排序数据列及排序方向
        this.GridView2.Attributes["SortExpression"] = sortExpression;
        this.GridView2.Attributes["SortDirection"] = sortDirection;

        this.BindSelectClass();
        GridviewControl.ResetGridView(this.GridView1);
    }

   
  
    protected void BindSelectClass()
    {
        int classtypeid = Convert.ToInt32(ddlclassType.SelectedValue);
        string keyword = txtkey.Text.Trim();
        if (!CoreTools.ProcessSqlStr(keyword, 0))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
        }
        else if (classtypeid != 0)
        {
            // 获取GridView排序数据列及排序方向
            string sortExpression = this.GridView2.Attributes["SortExpression"];
            string sortDirection = this.GridView2.Attributes["SortDirection"];
            DataSet ds = jtDataAccess.FilterClass(0, classtypeid, 5, keyword);
            if (CoreTools.CheckDataSet(ds))
            {
                // 根据GridView排序数据列及排序方向设置显示的默认数据视图
                if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
                {
                    ds.Tables[0].DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
                }

                // GridView绑定并显示数据
                GridviewControl.GridViewDataBind(this.GridView2, ds.Tables[0]);
                // pager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["Total"]);
                btnMassAdd.Enabled = true;
                selectAll.Enabled = true;

            }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ClassId");
                dt.Columns.Add("ClassTypeName");
                dt.Columns.Add("Code");
                dt.Columns.Add("Name");
                dt.Columns.Add("Time");
                dt.Columns.Add("");
                GridviewControl.GridViewDataBind(this.GridView2, dt);
                // pager1.RecordCount = 0;
                btnMassAdd.Enabled = false;
                selectAll.Enabled = false;

            }
        }
        else
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ClassId");
            dt.Columns.Add("ClassTypeName");
            dt.Columns.Add("Code");
            dt.Columns.Add("Name");
            dt.Columns.Add("Time");
            dt.Columns.Add("");
            GridviewControl.GridViewDataBind(this.GridView2, dt);
            // pager1.RecordCount = 0;
            btnMassAdd.Enabled = false;
            selectAll.Enabled = false;
        }
        GridviewControl.ResetGridView(this.GridView1);
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        BindSelectClass();
    }
    
    protected void btnreturn_Click(object sender, EventArgs e)
    {
        //Response.Redirect("Record1.aspx?MenuId=" + MenuId);
		Response.Redirect(returnURL);
    }
}